Skip to main content

Azure Deployment

Process to be followed for deploying the app on Azure

App convention

  • GQC has now switched to a convention where we have separate folders for the frontend of a project and the backend of the project.
  • For the ORSANCO project, we have separate folders namely,
    • orsanco_frontend
    • orsanco_backend
ORSANCO/
orsanco_frontend/
src/
components/
package.json

orsanco_backend/
riverflows/
...
manage.py
.gitignore
requirements.txt

⚠️ Sudhir prefers deploying the apps directly from VSCode.

Frontend

There are multiple ways to deploy the React App to Azure.

As an App Service

As a Static Web App SWA with GitHub Actions

  1. Create a SWA in the appropriate Resource Group
  2. If you wish to have Password Protection in your app
    1. Choose the Standard Tier
  3. Choose the account/organization
  4. Choose the repo
  5. Choose the branch
  6. And Click Deploy

Backend

Generating the SECRET_KEY

To generate a SECRET_KEY in Djano, use the following command.

from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())
# or directly run this command
python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'

Deploy as an App Service

  1. Create an App Service in the appropriate Resource Group
  2. Choose Python 3.9 as the stack and Linux as the Operating System
  3. To Deploy the App Service using CI through GitHub Actions,
    1. You will need to choose the B1 Tier for the App Service
  4. Choose the account/organization
  5. Choose the repo
  6. Choose the branch
  7. And Click Deploy

Setting environment variables in Azure

⚠️ Deploying the App Service without setting the variables of DEBUG and SECRET_KEY, the deployment will fail.

  1. Click on Configuration and add the following variables and their respective values
    SECRET_KEY = "secret key generated above"
    DEBUG = False
  2. In this app's case, the data comes from a Ubuntu VM running a PostgreSQL Database.
    DB_NAME = orsanco_flows
    DB_USER = gqc
    DB_PASSWORD = gqc010102
    DB_HOST = 20.14.140.39
    DB_PORT = 5432

Managing requirements.txt

  1. Before deploying, on your local system, run
    python manage.py check
    to make sure things (endpoints) are working as expected
  2. Create a requirements.txt using pipreqs or pip freeze
  3. ⚠️ With our current experience, both pipreqs and pip freeze have a hard time creating a proper requirements.txt
  4. Best way is to just create a new virutal environment locally and run
    python manage.py runserver
    and then iteratively add packages to the requirements.txt
  5. Not having the requirements.txt made correctly will result in a ModuleNotFoundError during deployment.